package scau.mis4.chanyulin.atm.physical;

import scau.mis4.chanyulin.atm.base.common.CODE;
import scau.mis4.chanyulin.atm.domain.Receipt;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by chanyulin on 2018/5/24.
 * 凭条打印机
 */
public class ReceiptPrinter {

    // 凭条输出队列
    private static List<Receipt> ejectedQueue;

    public ReceiptPrinter() {
        ejectedQueue = new LinkedList<>();
    }

    /**
     * 打印凭条
     * @param receipt
     * @return
     */
    public int print(Receipt receipt) {
        if (null == receipt) return CODE.ERR_NULL_POINTER;
        if (ejectedQueue.add(receipt))
            return CODE.MSG_SUCCESS;
        return CODE.MSG_FAILED;
    }

    /**
     * 取走所有凭条
     * @return
     */
    public static List<Receipt> takeAllReceipts() {
        List<Receipt> resultList = new LinkedList<>();
        resultList.addAll(ejectedQueue);
        clearAllReceipts();
        return resultList;
    }

    /**
     * 清空凭条输出队列
     */
    public static void clearAllReceipts() {
        ejectedQueue.clear();
    }

}
